#include "log_formatter.h"

#include <syslog.h>
#include <sstream>
#include <thread>
#include "log_level.h"
#include "time_util.h"

namespace Base {
namespace SystemLog {
void TimeFormatter::Format(LogStream &stream) const
{
    auto timeStr = Utils::TimeUtil::GetCurrentTimeString(format_);
    stream << timeStr;
}

void TimeFormatterWithMilliseconds::Format(LogStream &stream) const
{
    auto timeStr = Utils::TimeUtil::GetCurrentTimeStringWithMilliseconds(format_);
    stream << timeStr;
}

void LevelFormatter::Format(LogStream &stream) const
{
    stream << LogLevelToString(stream.GetLogLevel());
}

void ThreadIdFormatter::Format(LogStream &stream) const
{
    std::ostringstream oss;
    oss << std::this_thread::get_id();
    stream << oss.str();
}

void FileFormatter::Format(LogStream &stream) const
{
    stream << '[' << stream.GetFile() << ":" << stream.GetLine() << ']';
}

void MessageFormatter::Format([[maybe_unused]] LogStream &stream) const
{
    // 这是一个占位符，实际内容已经在LogStream中
    // 这个格式化器主要用于标记消息位置
}
} // namespace SystemLog
} // namespace Base